package com.comeval.persistencia;

import com.comeval.modelo.Pqrs;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Estudiante
 */
@Stateless
public class PqrsDAO implements IPqrsDAO {

    @PersistenceContext
    private EntityManager entityManager;

    @Override
    public void registrarPqrs(Pqrs pqrs) {
        try {
            entityManager.persist(pqrs);
        } catch (Exception e) {
            throw e;
        }
    }

    @Override
    public void modificarPqrs(Pqrs pqrs) {
        try {
            entityManager.merge(pqrs);
        } catch (Exception e) {
            throw e;
        }
    }

    @Override
    public void eliminarPqrs(Pqrs pqrs) {
        try {
            entityManager.remove(pqrs);
        } catch (Exception e) {
            throw e;
        }
    }

    @Override
    public List<Pqrs> consultarPqrs() {
     try {
            String jpql = "Select pqrs From Pqrs pqrs";
            Query query = entityManager.createQuery(jpql);
            return query.getResultList();
        } catch (Exception e) {
            throw e;
        }
    }

    @Override
    public Pqrs consultarPorCodigo(Integer codigoPqrs) {
       try {
            return entityManager.find(Pqrs.class, codigoPqrs);
        } catch (Exception e) {
            throw e;
        }
    }

}
